package com.example.MyThread.ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Jason
 * @PACKAGE_NAME com.example.MyThread.ThreadPool
 * @Description
 * @date 2023-12-11 14:01
 */
public class Demo {
    /**
     * public static ExecutorService newCachedThreadPool()
     * public static ExecutorService newFixedThreadPool(int nThreads)
     */


    public static void main(String[] args) throws InterruptedException {

        //1.创建线程池
//        ExecutorService pool = Executors.newCachedThreadPool();
        ExecutorService pool = Executors.newFixedThreadPool(3);
        //2.提交任务
        pool.execute(new MyRunnable());
        pool.execute(new MyRunnable());
        pool.execute(new MyRunnable());
        pool.execute(new MyRunnable());
        pool.execute(new MyRunnable());
        pool.execute(new MyRunnable());
        pool.execute(new MyRunnable());
//        Thread.sleep(1000);
//        pool.execute(new MyRunnable());
//        Thread.sleep(1000);
//        pool.execute(new MyRunnable());
//        Thread.sleep(1000);
//        pool.execute(new MyRunnable());
//        Thread.sleep(1000);
//        pool.execute(new MyRunnable());
//        Thread.sleep(1000);
//        pool.execute(new MyRunnable());
        //3.销毁线程池
        pool.shutdown();

    }

}
